

package com.hazelcast.map.impl.record;

import com.hazelcast.internal.serialization.Data;

import static com.hazelcast.internal.util.JVMUtil.REFERENCE_COST_IN_BYTES;

class DataRecordWithStats extends AbstractRecord<Data> {
    protected volatile Data value;

    DataRecordWithStats() {
    }

    DataRecordWithStats(Data value) {
        setValue(value);
    }

    /**
     * Get record size in bytes.
     */
    @Override
    public long getCost() {
        return super.getCost() + REFERENCE_COST_IN_BYTES + (value == null ? 0L : value.getHeapCost());
    }

    @Override
    public Data getValue() {
        return value;
    }

    @Override
    public void setValue(Data o) {
        value = o;
    }

    @Override
    public boolean equals(Object o) {
        if (!super.equals(o)) {
            return false;
        }

        DataRecordWithStats that = (DataRecordWithStats) o;
        return value.equals(that.value);
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + value.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "DataRecordWithStats{" + "value=" + value + ", " + super.toString() + "} ";
    }
}
